package com.whty.module.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.whty.framework.shiro.service.PasswordService;
import com.whty.system.domain.SysUser;
import com.whty.system.mapper.SysUserMapper;

/**
 * 客户 服务层实现
 * 
 * @author mario
 * @date 2018-10-23
 */
@Service
public class UserServiceImpl implements IUserService 
{
     @Autowired 
     SysUserMapper sysUserMapper;  
     @Autowired
     private PasswordService passwordService;
	 
	@Override
	public String userLogin(JSONObject msg) {
		JSONObject json=new JSONObject();
	 String userName=msg.getString("userName");
	 String userPass=msg.getString("userPass");
	 SysUser sysUser=sysUserMapper.selectUserByLoginName(userName);
	 if(sysUser==null)
	 {
		 json.put("return_code", "SUCCESS");
		 json.put("return_msg", "OK");
		 json.put("result_code", "FAIL");
		 json.put("error_code", "LOGINFAIL");
		 json.put("error_msg", "用户名不存在");
	 }else
	 {
		 boolean login_result=passwordService.matches(sysUser, userPass);
		 if(login_result)
		 {
			 json.put("return_code", "SUCCESS");
			 json.put("return_msg", "登录成功");
			 json.put("result_code", "SUCCESS");
			 json.put("userId", sysUser.getUserId());
		 }else
		 {
			 json.put("return_code", "SUCCESS");
			 json.put("return_msg", "OK");
			 json.put("result_code", "FAIL");
			 json.put("error_code", "LOGINFAIL");
			 json.put("error_msg", "用户名或密码无效");
		 }
		
	 }
		return json.toString();
	}

	
}
